package org.KeyCrafter.util;

import static org.KeyCrafter.server.ServerConstants.KeyCrafter_LRU_CLOCK_MAX;
import static org.KeyCrafter.server.ServerConstants.KeyCrafter_LRU_CLOCK_RESOLUTION;

/**
 * 用于获取当前时间
 * 注意:
 *      此时间不是实时获取的，Redis以1秒为周期执行系统调用获取精确时间
 */
public final class TimeUtil {
    public static int getLRUClock() {
        return (mstime() / KeyCrafter_LRU_CLOCK_RESOLUTION) & KeyCrafter_LRU_CLOCK_MAX;
    }

    public static long microTime() {
        return System.nanoTime() / 1000;
    }

    // 返回毫秒格式的 UNIX 时间
    private static int mstime() {
        return (int) (System.currentTimeMillis() & 0x7FFFFFFFL);
    }

    private TimeUtil() {
    }
}
